Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add an async getUser function to Auth0ContextInterface #816

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MisterSquishy
Copy link

Description

the Auth0ContextInterface provides auth state and a bunch of async methods for updating that auth state. the user, however, is only populated in state as a side effect of other methods (namely getAccessTokenSilently, getAccessTokenWithPopup, and handleRedirectCallback) which means there is no way for a client to guarantee they have access when they first mount the hook. the standard way to deal with this is with an effect -- mount the hook, call getAccessTokenSilently or something, and rerender when the user is fetched. however, this isnt always possible, for instance tanstack router's beforeLoad method is a place where it would be really useful to await a user (to determine if they have access to this specific route). as of now, this library provides no way to do this, so i added this quick wrapper around the client.getUser method, for use in contexts where we cant rely on rerenders.

Testing

i relied on unit tests to test this, but theyre not particularly inspired -- given that this function just wraps client.getUser there really isnt much to test here.

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation for new/changed functionality in this PR or in auth0.com/docs
    • i didnt, but i can if it's deemed useful... i noticed that there are a handful of simple/self-explanatory methods that arent specifically called out in the examples, e.g. getAccessTokenWithPopup
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not the default branch

@MisterSquishy MisterSquishy requested a review from a team as a code owner November 23, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant